import { makeAutoObservable } from "mobx";
import axios from "../utils/axios";
class AfterSales {
  data = [];
  total = 0;
  pagemoren = 1;
  constructor() {
    makeAutoObservable(this);
  }
  //高级搜索
  gaosousuo = (obj) => {
    axios({
      method: "get",
      url: "/after_sales/findSalesByCustomerHigh",
      params: {
        currentPage: 1,
        pageSize: 10,
        customer_id: obj.customer_id,
        customer_name: obj.customer_name,
        contact_name: obj.contact_name,
        after_classification: obj.after_classification,
        feedback_theme: obj.feedback_theme,
        comment: obj.comment,
        feedback_time: obj.feedback_time,
        handling_time: obj.handling_time,
        after_state: obj.after_state,
        user_name: obj.user_name,
      },
    }).then((res) => {
      if (res.data.code === 200) {
        this.data = [...res.data.data];
        console.log(res);
      }
      /*  this.data = [...res.data.data]; */
    });
  };
  //修改
  edit = (obj, Id, dex) => {
    let objdata = {
      sale_id: Id,
      related_products: obj.related_products,
      feedback_theme: obj.feedback_theme,
      after_classification: obj.after_classification,
      contact_name: obj.contact_name,
      feedback_time: obj.feedback_time,
      comment: obj.comment,
      after_state: obj.after_state,
      handling_time: obj.handling_time,
      result_handling: obj.result_handling,
    };
    console.log(objdata);
    axios({
      method: "post",
      url: "/after_sales/updateSalesMessage",
      data: objdata,
    }).then((res) => {
      let page = 1;
      if (dex === 0) {
        this.Processedlist(page);
      } else if (dex === 1) {
        this.Processinglist(page);
      } else if (dex === 2) {
        this.Untreatedlist(page);
      } else {
        this.Afterlist(page);
      }
      console.log(res + "编辑");

      /*  this.data = [...res.data.data]; */
    });
  };
  //新增售后记录
  upda = (obj) => {
    console.log(obj.after_state);
    axios({
      method: "post",
      url: "/after_sales/addSales",
      params: {
        customer_id: 7,
        customer_name: obj.customer_name,
        related_products: obj.related_products,
        feedback_theme: obj.feedback_theme,
        after_classification: obj.after_classification,
        contact_name: obj.contact_name,
        feedback_time: obj.feedback_time,
        comment: obj.comment,
        after_state: Number(obj.after_state),
        handling_time: obj.handling_time,
        result_handling: obj.result_handling,
        user_name: "超级管理员",
      },
    }).then((res) => {
      console.log(res);
      console.log(obj);
      /*  this.data = [...res.data.data]; */
    });
  };
  //select普通搜索
  selectlist = (condition) => {
    axios({
      method: "get",
      url: "/after_sales/findSalesByCustomer",
      params: {
        currentPage: 1,
        pageSize: 10,
        condition: condition,
      },
    }).then((res) => {
      if (res.data.code === 200) {
        this.data = [...res.data.data];
        console.log(res);
      }
    });
  };
  /* 删除 */
  del = (id, dex) => {
    axios({
      method: "post",
      url: "/after_sales/delSalesMessage",
      params: {
        sale_id: id,
      },
    }).then((res) => {
      console.log(res + "删除");
      let page = 1;
      if (dex === 0) {
        this.Processedlist(page);
      } else if (dex === 1) {
        this.Processinglist(page);
      } else if (dex === 2) {
        this.Untreatedlist(page);
      } else {
        this.Afterlist(page);
      }
    });
  };
  /* 售后列表 */
  Afterlist = (page) => {
    axios({
      url: "/after_sales/allsales/findSalesMessage",
      params: {
        currentPage: page,
        pageSize: 10,
      },
    }).then((res) => {
      console.log(res.data.count);
      if (res.data.code === 200) {
        this.total = res.data.count;
        this.data = [...res.data.data];
        console.log(res);
      }
    });
  };
  /* 已处理 */
  Processedlist = (page) => {
    axios({
      url: "/after_sales/finishsales/findSalesMessageByProcessed",
      params: {
        currentPage: page,
        pageSize: 10,
        after_state: 2,
        status: 0,
      },
    }).then((res) => {
      if (res.data.code === 200) {
        this.total = res.data.count;
        this.data = [...res.data.data];
        console.log(res.data);
      }
    });
  };
  /* 处理中 */
  Processinglist = (page) => {
    axios({
      url: "/after_sales/ongoingsales/findSalesMessageByBeing",
      params: {
        currentPage: page,
        pageSize: 10,
        after_state: 1,
        status: 0,
      },
    }).then((res) => {
      if (res.data.code === 200) {
        this.total = res.data.count;
        this.data = [...res.data.data];
        console.log(res.data);
      }
    });
  };
  /* 未处理 */
  Untreatedlist = (page) => {
    axios({
      url: "/after_sales/conductsales/findSalesMessageByUntreated",
      params: {
        currentPage: page,
        pageSize: 10,
        after_state: 0,
        status: 0,
      },
    }).then((res) => {
      console.log(res.data);
      console.log(res.data.code);
      if (res.data.code === 200) {
        this.total = res.data.count;
        this.data = [...res.data.data];
      }
    });
  };
}
export default AfterSales;
